package com.haibei.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.haibei.R;
import com.haibei.adapter.bean.SortBean;

public class SortAdapter extends BaseAdapter {

	private Context mContext;
	private ArrayList<SortBean> mArrayList;
	private static int index = -1;

	public SortAdapter(Context context, ArrayList<SortBean> sortBeans) {
		this.mContext = context;
		this.mArrayList = sortBeans;
	}

	@Override
	public int getCount() {
		return mArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		return mArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolderSub vhg = null;
		if (null == convertView) {
			convertView = View.inflate(mContext, R.layout.item_sift_sub, null);
			vhg = new ViewHolderSub();
			vhg.imageViewSub = (ImageView) convertView.findViewById(R.id.imageViewHookSub);
			vhg.textViewParentSub = (TextView) convertView.findViewById(R.id.textViewLocationSub);
			convertView.setTag(vhg);
		} else {
			vhg = (ViewHolderSub) convertView.getTag();
		}
		SortBean sb = mArrayList.get(position);
		if (index == position) {
			vhg.imageViewSub.setImageResource(R.drawable.bg_radio_check);
		} else {
			vhg.imageViewSub.setImageResource(R.drawable.bg_radio_uncheck);
		}
		vhg.textViewParentSub.setText(sb.getText());
		return convertView;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
		notifyDataSetChanged();
	}

	class ViewHolderSub {
		TextView textViewParentSub;
		ImageView imageViewSub;
	}
}
